//
//  HomePageViewController.m
//  STL_ Animation
//
//  Created by DJtd on 16/3/29.
//  Copyright © 2016年 STL. All rights reserved.
//

#import "HomePageViewController.h"
#import "STL.h"
#import "HomePageMainTableViewCell.h"
#import "HomePageBaseModel.h"
#import "MJRefreshGifHeader.h"
#import "HomeSTLPageTableViewCell.h"
#import "YMVViewController.h"

@interface HomePageViewController ()<UITableViewDelegate, UITableViewDataSource, STLScrollViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UITableView *STLtableView;

@property (nonatomic, strong) UIView *descView;

@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) NSMutableArray *dataSourceSTL;
@property (nonatomic, assign) NSInteger page;
@property (nonatomic, assign) NSInteger pageSTL;
//按钮
@property (nonatomic, strong) UIButton *buttonRecommend;
@property (nonatomic, strong) UIButton *buttonPremiere;
@property (nonatomic, strong) UIButton *buttonPopular;
@property (nonatomic, strong) UIButton *buttonProgram;
@property (nonatomic, strong) UIButton *buttonFans;
//
@property (nonatomic, strong) STLScrollView *stlScroll1;
@property (nonatomic, strong) STLScrollView *stlScroll2;
@property (nonatomic, strong) STLScrollView *stlScroll3;
@property (nonatomic, strong) STLScrollView *stlScroll4;


@property (nonatomic, assign) NSInteger NUM1;
@property (nonatomic, assign) NSInteger NUM2;
@property (nonatomic, assign) NSInteger NUM3;
@property (nonatomic, assign) NSInteger NUM4;

@property (nonatomic, assign) NSInteger ButtonNum;

@property (nonatomic, strong) NSString *area;
@property (nonatomic, strong) NSString *areaTwo;
@property (nonatomic, strong) NSString *areaThree;
@property (nonatomic, strong) NSString *areaFour;


@property (nonatomic, assign) BOOL isRequest;
@property (nonatomic, assign) BOOL isOneRequest;
@property (nonatomic, assign) BOOL isTwoRequest;
@property (nonatomic, assign) BOOL isThreeRequest;

@property (nonatomic, strong) NSTimer *timer;

@end


@implementation HomePageViewController


- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"首页";
    self.dataSource = [NSMutableArray arrayWithCapacity:0];
    self.dataSourceSTL = [NSMutableArray arrayWithCapacity:0];
    self.page = 0;
    self.pageSTL = 0;
    self.NUM1 = 0;
    self.NUM2 = 0;
    self.NUM3 = 0;
    self.NUM4 = 0;
    self.ButtonNum = 1;
    self.area = @"ALL";
    self.areaTwo = @"ALL";
    self.areaThree = @"30971,36771,32393,21713";
    self.areaFour = @"ALL";
    self.isRequest = NO;
    self.isOneRequest = NO;
    self.isTwoRequest = NO;
    self.isThreeRequest = NO;

    
    [self creatSTLScrollViewWithArray:ArrPREMIERE withIndex:3];
    [self creatSTLScrollView2WithArray:ArrPREMIERE withIndex:3];
    [self creatSTLScrollView3WithArray:ArrPROGRAM withIndex:2];
    [self creatSTLScrollView4WithArray:ArrFANS withIndex:2];

    [self removeScrollView];
    
    [self creatTableView];
    [self descView];
    [self creatButton];
    
    [self request];
    
    
}


#pragma mark - 首页网络请求
- (void)request {
    
    NSString *url = @"http://mapi.yinyuetai.com/suggestions/front_page.json?D-A=12&offset=%ld&play=false&rn=640*540&size=10&v=3";
    
    NSString *URL = [NSString stringWithFormat:url, self.page];
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [SJAFNetTool GEtNetWithUrl:URL WithBody:nil headerFile:Dictionary response:SJJSON success:^(id result) {
        
        

        if (result) {
            if (self.isRequest == YES) {
                [self.dataSource removeAllObjects];
                self.isRequest = NO;
            }
        for (NSDictionary *dic in result) {
            HomePageBaseModel *homeModel = [[HomePageBaseModel alloc] initWithDataSource:dic];
            if ([homeModel.type isEqualToString:@"PLAYLIST"] || [homeModel.type isEqualToString:@"FANART"] || [homeModel.type isEqualToString:@"VIDEO"] || [homeModel.type isEqualToString:@"PROGRAM"]) {
                
                [self.dataSource addObject:homeModel];
            }
        }
        
        [self.tableView reloadData];
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD showAlertView:@"" andMessage:@"网络错误"];
    }];
    
}

#pragma mark - 其他页面网络请求
- (void)requestOtherWithArea:(NSString *)area {
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    
    NSString *URL;
    switch (self.ButtonNum) {
        case 2:
        {   NSString *url = @"http://mapi.yinyuetai.com/video/list.json?D-A=0&area=%@&offset=%ld&size=20";
            URL = [NSString stringWithFormat:url, area, self.pageSTL];
        }   break;
        case 3:
        {    NSString *url = @"http://mapi.yinyuetai.com/video/list.json?D-A=0&area=POP_%@&offset=%ld&size=20";
            URL = [NSString stringWithFormat:url, area, self.pageSTL];
        }  break;
        case 4:
        {   NSString *url = @"http://mapi.yinyuetai.com/artist/much_videos.json?D-A=0&artistIds=[%@]&offset=%ld&size=20";
            URL = [NSString stringWithFormat:url, area, self.pageSTL];
        }   break;
        case 5:
        {   NSString *url = @"http://mapi.yinyuetai.com/suggestions/fan_focus.json?D-A=0&offset=%ld&size=20&type=%@";
            URL = [NSString stringWithFormat:url, self.pageSTL, area];
        }   break;
        default:
            break;
    }
    
   
    [SJAFNetTool GEtNetWithUrl:URL WithBody:nil headerFile:Dictionary response:SJJSON success:^(id result) {
        

        if (result) {

            if (self.isOneRequest == YES) {
                [self.dataSourceSTL removeAllObjects];
                self.isOneRequest = NO;
            }
            
            for (NSDictionary *dic in result[@"videos"]) {
                
                HomePageBaseModel *homeModel = [[HomePageBaseModel alloc] initWithDataSource:dic];
                

                if (![homeModel.title isEqualToString:@""]) {
                    [self.dataSourceSTL addObject:homeModel];

                }
                
            }
        [self.STLtableView reloadData];
        [self.STLtableView.mj_header endRefreshing];
        [self.STLtableView.mj_footer endRefreshing];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD showAlertView:@"" andMessage:@"网络错误"];
    }];
}


#pragma mark - 刷新请求
- (void)upRequest {
    self.page = 0;
    self.isRequest = YES;
    [self request];
    [self.tableView.mj_header endRefreshing];
}
- (void)downRequest {
    self.page += 10;
    [self request];
    [self.tableView.mj_footer endRefreshing];
}
- (void)upSTLRequest {
    self.pageSTL = 0;
    self.isOneRequest = YES;
    [self requestWithArea];
    [self.tableView.mj_header endRefreshing];
}
- (void)downSTLRequest {
    self.pageSTL += 20;
    [self requestWithArea];
    [self.tableView.mj_footer endRefreshing];
}
- (void)requestWithArea {
    switch (self.ButtonNum) {
        case 2:
        {
            [self requestOtherWithArea:self.area];
        }   break;
        case 3:
        {
            [self requestOtherWithArea:self.areaTwo];
        }  break;
        case 4:
        {
            [self requestOtherWithArea:self.areaThree];
        }   break;
        case 5:
        {
            [self requestOtherWithArea:self.areaFour];
        }   break;
        default:
            break;
    }
}


#pragma mark - 点击
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    
    //悦单mv播放页
    YMVViewController *YMVvc = [[YMVViewController alloc] init];

    
    
    
    ChannelPageMV_ViewController *ChanVC = [[ChannelPageMV_ViewController alloc] init];
    //
    switch (self.ButtonNum) {
        case 1:
        {
            HomePageBaseModel *model = self.dataSource[indexPath.row];
            if ([model.type isEqualToString:@"PLAYLIST"]) {
                YMVvc.homeModel = model;
                [self.navigationController pushViewController:YMVvc animated:YES];
            } else {
                ChanVC.idName = model._id.stringValue;
                [self.navigationController pushViewController:ChanVC animated:YES];
            }
        }   break;
        case 2:
        {
            HomePageBaseModel *twoModel = self.dataSourceSTL[indexPath.row];
            ChanVC.idName = twoModel._id.stringValue;
            [self.navigationController pushViewController:ChanVC animated:YES];
        }   break;
        case 3:
        {
            HomePageBaseModel *twoModel = self.dataSourceSTL[indexPath.row];
            ChanVC.idName = twoModel._id.stringValue;
            [self.navigationController pushViewController:ChanVC animated:YES];
        }  break;
        case 4:
        {
            HomePageBaseModel *twoModel = self.dataSourceSTL[indexPath.row];
            ChanVC.idName = twoModel._id.stringValue;
            [self.navigationController pushViewController:ChanVC animated:YES];
        }   break;
        case 5:
        {
            HomePageBaseModel *twoModel = self.dataSourceSTL[indexPath.row];
            ChanVC.idName = twoModel._id.stringValue;
            [self.navigationController pushViewController:ChanVC animated:YES];
        }   break;
        default:
            break;
    }


}




#pragma mark - 创建tableview
- (void)creatTableView {
    if (self.STLtableView) {
        [self.STLtableView removeFromSuperview];
    }
    [self removeScrollView];

    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 64) style:UITableViewStylePlain];
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:self.tableView];
    //刷新
    [self.tableView setMj_header:[MJRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(upRequest)]];
    //
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(downRequest)];
    
    UINib *nib = [UINib nibWithNibName:@"HomePageMainTableViewCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:@"maincell"];
    
    //
    [self.view bringSubviewToFront:self.descView];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (tableView == self.tableView) {
        HomePageMainTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"maincell"];
        
        cell.homeModel = self.dataSource[indexPath.row];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        if ([cell.homeModel.type isEqualToString:@"PLAYLIST"]) {
            cell.typeImage.image = [[UIImage imageNamed:@"yuelist"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        } else {
            cell.typeImage.image = [[UIImage imageNamed:@"hotplay"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        }
        return cell;
    }
    
    else {
        
        HomeSTLPageTableViewCell *STLcell = [tableView dequeueReusableCellWithIdentifier:@"STLcell"];
        
        STLcell.selectionStyle = UITableViewCellSelectionStyleNone;

        STLcell.homeModel = self.dataSourceSTL[indexPath.row];
        return STLcell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.tableView) {
        return (ScreenHeight / 2 - 20);
    }
    return (ScreenHeight - 64 - ScreenHeight * 0.045) / 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView == self.tableView) {
        return self.dataSource.count;
    } else {
        return self.dataSourceSTL.count;
    }
}


#pragma mark - 仿tabbar－view
- (UIView *)descView {
    if (!_descView) {
        self.descView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight - 113, ScreenWidth, 49)];
        self.descView.backgroundColor = [UIColor blackColor];
        [self.view addSubview:self.descView];
    }
    return _descView;
}



#pragma mark - 创建button
- (void)creatButton {
    //推荐recommend 首播Premiere 流行popular 节目program 粉丝fans
    self.buttonRecommend = [UIButton buttonWithType:UIButtonTypeSystem];
    self.buttonPremiere = [UIButton buttonWithType:UIButtonTypeSystem];
    self.buttonPopular = [UIButton buttonWithType:UIButtonTypeSystem];
    self.buttonProgram = [UIButton buttonWithType:UIButtonTypeSystem];
    self.buttonFans = [UIButton buttonWithType:UIButtonTypeSystem];
    
    //button大小 1/12 屏宽
    self.buttonRecommend.frame = CGRectMake(ScreenWidth / 50 * 3, 10, ScreenWidth / 25 * 2, ScreenWidth / 25 * 2);
    self.buttonPremiere.frame = CGRectMake(ScreenWidth / 50 * 13, 10, ScreenWidth / 25 * 2, ScreenWidth / 25 * 2);
    self.buttonPopular.frame = CGRectMake(ScreenWidth / 50 * 23, 10, ScreenWidth / 25 * 2, ScreenWidth / 25 * 2);
    self.buttonProgram.frame = CGRectMake(ScreenWidth / 50 * 33, 10, ScreenWidth / 25 * 2, ScreenWidth / 25 * 2);
    self.buttonFans.frame = CGRectMake(ScreenWidth / 50 * 43, 10, ScreenWidth / 25 * 2, ScreenWidth / 25 * 2);
    
    
    //button 赋初始图片
    [self settingImageOne:@"Image-2" imageTwo:@"Image-3" imageThree:@"Image-5" imageFour:@"Image-7" imageFive:@"Image-9"];
    
    [self.descView addSubview:self.buttonRecommend];
    [self.descView addSubview:self.buttonPremiere];
    [self.descView addSubview:self.buttonPopular];
    [self.descView addSubview:self.buttonProgram];
    [self.descView addSubview:self.buttonFans];
    
    
    [self.buttonRecommend addTarget:self action:@selector(recommend) forControlEvents:UIControlEventTouchUpInside];
    [self.buttonPremiere addTarget:self action:@selector(premiere) forControlEvents:UIControlEventTouchUpInside];
    [self.buttonPopular addTarget:self action:@selector(popular) forControlEvents:UIControlEventTouchUpInside];
    [self.buttonProgram addTarget:self action:@selector(program) forControlEvents:UIControlEventTouchUpInside];
    [self.buttonFans addTarget:self action:@selector(fans) forControlEvents:UIControlEventTouchUpInside];

    
}

#pragma mark - 按钮赋图
- (void)settingImageOne:(NSString *)imageOne imageTwo:(NSString *)imageTwo imageThree:(NSString *)imageThree imageFour:(NSString *)imageFour imageFive:(NSString *)imageFive {
    [self.buttonRecommend setImage:[[UIImage imageNamed:imageOne] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
    [self.buttonPremiere setImage:[[UIImage imageNamed:imageTwo] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
    [self.buttonPopular setImage:[[UIImage imageNamed:imageThree] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
    [self.buttonProgram setImage:[[UIImage imageNamed:imageFour] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
    [self.buttonFans setImage:[[UIImage imageNamed:imageFive] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
}




#pragma mark - 按钮点击事件
- (void)recommend {
    self.ButtonNum = 1;
    [self settingImageOne:@"Image-2" imageTwo:@"Image-3" imageThree:@"Image-5" imageFour:@"Image-7" imageFive:@"Image-9"];
    [self removeScrollView];
    
    [self.STLtableView removeFromSuperview];
    [self.dataSourceSTL removeAllObjects];
    
    self.tableView.hidden = NO;
}
- (void)premiere {
    self.ButtonNum = 2;
    self.pageSTL = 0;
    [self settingImageOne:@"Image-1" imageTwo:@"Image-4" imageThree:@"Image-5" imageFour:@"Image-7" imageFive:@"Image-9"];
    self.tableView.hidden = YES;
    if (self.STLtableView) {
        [self.STLtableView removeFromSuperview];
    }
    [self.dataSourceSTL removeAllObjects];
    
    [self creatSTLtableView];
    [self requestOtherWithArea:self.area];
    [self removeScrollView];
    self.stlScroll1.hidden = NO;
    [self.view bringSubviewToFront:self.stlScroll1];
}
- (void)popular {
    self.ButtonNum = 3;
    self.pageSTL = 0;
    [self settingImageOne:@"Image-1" imageTwo:@"Image-3" imageThree:@"Image-6" imageFour:@"Image-7" imageFive:@"Image-9"];
    if (self.STLtableView) {
        [self.STLtableView removeFromSuperview];
    }
    self.tableView.hidden = YES;
    [self.dataSourceSTL removeAllObjects];
    
    [self creatSTLtableView];
    [self requestOtherWithArea:self.areaTwo];
    [self removeScrollView];
    self.stlScroll2.hidden = NO;
    [self.view bringSubviewToFront:self.stlScroll2];
}
- (void)program {
    self.ButtonNum = 4;
    self.pageSTL = 0;
    [self settingImageOne:@"Image-1" imageTwo:@"Image-3" imageThree:@"Image-5" imageFour:@"Image-8" imageFive:@"Image-9"];
    if (self.STLtableView) {
        [self.STLtableView removeFromSuperview];
    }
    self.tableView.hidden = YES;
    [self.dataSourceSTL removeAllObjects];

    [self creatSTLtableView];
    [self requestOtherWithArea:self.areaThree];
    [self removeScrollView];
    self.stlScroll3.hidden = NO;
    [self.view bringSubviewToFront:self.stlScroll3];
}
- (void)fans {
    self.ButtonNum = 5;
    self.pageSTL = 0;
    [self settingImageOne:@"Image-1" imageTwo:@"Image-3" imageThree:@"Image-5" imageFour:@"Image-7" imageFive:@"Image-10"];
    if (self.STLtableView) {
        [self.STLtableView removeFromSuperview];
    }
    self.tableView.hidden = YES;
    [self.dataSourceSTL removeAllObjects];

    [self creatSTLtableView];
    [self requestOtherWithArea:self.areaFour];
    [self removeScrollView];
    self.stlScroll4.hidden = NO;
    [self.view bringSubviewToFront:self.stlScroll4];
}


#pragma mark - 隐藏滚动条
- (void)removeScrollView {
    if (self.stlScroll1) {
        self.stlScroll1.hidden = YES;
    }
    if (self.stlScroll2) {
        self.stlScroll2.hidden = YES;
    }
    if (self.stlScroll3) {
        self.stlScroll3.hidden = YES;
    }
    if (self.stlScroll4) {
        self.stlScroll4.hidden = YES;
    }
}

#pragma makr- 滑动条1
- (void)creatSTLScrollViewWithArray:(NSArray *)array withIndex:(NSInteger)index {
    self.stlScroll1 = [[STLScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight * 0.045) withTextArr:array withIndex:index];
    self.stlScroll1.delegate = self;
    [self.view addSubview:self.stlScroll1];
}
#pragma makr- 滑动条2
- (void)creatSTLScrollView2WithArray:(NSArray *)array withIndex:(NSInteger)index {
    self.stlScroll2 = [[STLScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight * 0.045) withTextArr:array withIndex:index];
    self.stlScroll2.delegate = self;
    [self.view addSubview:self.stlScroll2];
}
#pragma makr- 滑动条3
- (void)creatSTLScrollView3WithArray:(NSArray *)array withIndex:(NSInteger)index {
    self.stlScroll3 = [[STLScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight * 0.045) withTextArr:array withIndex:index];
    self.stlScroll3.delegate = self;
    [self.view addSubview:self.stlScroll3];
}
#pragma makr- 滑动条4
- (void)creatSTLScrollView4WithArray:(NSArray *)array withIndex:(NSInteger)index {
    self.stlScroll4 = [[STLScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight * 0.045) withTextArr:array withIndex:index];
    self.stlScroll4.delegate = self;
    [self.view addSubview:self.stlScroll4];
}


#pragma mark - 记住滑条位置
- (void)indexOfDetailId:(NSInteger)detailId {
    self.pageSTL = 0;
    if (self.ButtonNum == 2) {
        [self.dataSourceSTL removeAllObjects];
        self.area = ArrScrOne[detailId];
        [self requestOtherWithArea:self.area];
    }
    else if (self.ButtonNum == 3) {
        [self.dataSourceSTL removeAllObjects];
        self.areaTwo = ArrScrOne[detailId];
        [self requestOtherWithArea:self.areaTwo];
    }
    else if (self.ButtonNum == 4) {
        [self.dataSourceSTL removeAllObjects];
        self.areaThree = ArrScrTwo[detailId];
        [self requestOtherWithArea:self.areaThree];
    }
    else if (self.ButtonNum == 5) {
        [self.dataSourceSTL removeAllObjects];
        self.areaFour = ArrScrThree[detailId];
        [self requestOtherWithArea:self.areaFour];
    }
}

#pragma mark - 创建STLtableView
- (void)creatSTLtableView {
    self.tableView.hidden = YES;
    
    self.STLtableView = [[UITableView alloc] initWithFrame:CGRectMake(0, ScreenHeight * 0.045, ScreenWidth, ScreenHeight - 64 - ScreenHeight * 0.045) style:UITableViewStylePlain];
    self.STLtableView.delegate = self;
    self.STLtableView.dataSource = self;
    self.STLtableView.showsVerticalScrollIndicator = NO;
    self.STLtableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.STLtableView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:self.STLtableView];
    //刷新
    [self.STLtableView setMj_header:[MJRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(upSTLRequest)]];
    //
    
    self.STLtableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(downSTLRequest)];
    
    
    UINib *nib = [UINib nibWithNibName:@"HomeSTLPageTableViewCell" bundle:nil];
    [self.STLtableView registerNib:nib forCellReuseIdentifier:@"STLcell"];
    //
    [self.view bringSubviewToFront:self.descView];
}



#pragma mark - 监听tableview滚动
float lastContentOffset;
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    lastContentOffset = scrollView.contentOffset.y;
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
    if (lastContentOffset < scrollView.contentOffset.y) {
        self.descView.frame = CGRectMake(0, ScreenHeight - 113, ScreenWidth, 49);
//        [UIView animateWithDuration:2 animations:^{
//            
//            CGRect frame = self.descView.frame;
//            frame.origin.y += frame.size.height;
//            self.descView.frame = frame;
//        }];
        self.descView.hidden = YES;
    }
    else {
//        [UIView animateWithDuration:1 animations:^{
//            
//            CGRect frame = self.descView.frame;
//            frame.origin.y -= self.descView.bounds.size.height;
//            self.descView.frame = frame;
//        }];
        self.descView.hidden = NO;
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    self.timer = [NSTimer scheduledTimerWithTimeInterval:2.0f  target:self selector:@selector(descViewHidden) userInfo:nil repeats:NO];
}
- (void)descViewHidden {
    self.descView.hidden = NO;
//    [UIView animateWithDuration:1 animations:^{
//        
//        CGRect frame = self.descView.frame;
//        frame.origin.y -= self.descView.bounds.size.height;
//        self.descView.frame = frame;
//    }];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
